import { CHANNEL_GET_LIST, CHANNEL_SET_INDEX } from '../action/actionTypes';

//  1.4. 将channel reducer分拆到单独的文件中维护
const initState = {
  list: [],
  activeIndex: 0,
};
export default function channelReducer(state = initState, action) {
  const { type, payload } = action;
  // 3.3 reducer中处理对应的action-更新list
  switch (type) {
    // 5.2 使用常量替换字符串
    case CHANNEL_GET_LIST:
      return { ...state, list: [...payload] };
    // 4.3 reducer中处理setActiveIndex 对应的操作
    case CHANNEL_SET_INDEX:
      return {
        ...state,
        activeIndex: payload,
      };
    default:
      return state;
  }
}
